<?php
include_once '../meihe/common.php';
if ($islogin == 1) {
} else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
<?php
if (isset($_GET['kw'])) {
    $kw = daddslashes($_GET['kw']);
    if ($_GET['type'] == 1)
        $sql = ($_GET['method'] == 1) ? " `zid` LIKE '%{$kw}%'" : " `zid`='{$kw}'";
    elseif ($_GET['type'] == 2)
        $sql = ($_GET['method'] == 1) ? " `user` LIKE '%{$kw}%'" : " `user`='{$kw}'";
    elseif ($_GET['type'] == 3)
        $sql = ($_GET['method'] == 1) ? " `qq` LIKE '%{$kw}%'" : " `qq`='{$kw}'";
    else {
        if (is_numeric($kw)) $column = 'qq';
        $sql = ($_GET['method'] == 1) ? " `{$column}` LIKE '%{$kw}%'" : " `{$column}`='{$kw}'";
    }
    $numrows = $DB->count("SELECT count(*) from meihe_user WHERE{$sql}");
    $con = '包含 ' . $kw . ' 的共有 <b>' . $numrows . '</b> 个用户';
    $link = '&kw=' . $_GET['kw'];
} elseif (isset($_GET['zid'])) {
    $zid = intval($_GET['zid']);
    $sql = " `zid`='{$zid}'";
    $numrows = $DB->count("SELECT count(*) from meihe_user WHERE{$sql}");
    $con = '用户(zid:' . $zid . ')共有 <b>' . $numrows . '</b> 个下级';
    $link = '&zid=' . $_GET['zid'];
} else {
    $numrows = $DB->count("SELECT count(*) from meihe_user WHERE 1");
    $sql = " 1";
    $con = '平台共有 <b>' . $numrows . '</b> 个用户';
}
?>
<div style="white-space:nowrap;overflow-x: auto;">
    <table class="layui-table layuiadmin-page-table">
        <thead>
            <tr>
                <th>用户zid</th>
                <th>用户头像</th>
                <th>用户权限</th>
                <th>用户名</th>
                <th>用户QQ</th>
                <th>用户余额</th>
                <th>添加/到期时间</th>
                <th>是否封禁</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <?php
            $pagesize = isset($_GET['num']) ? intval($_GET['num']) : 30;
            $pages = ceil($numrows / $pagesize);
            $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
            $offset = $pagesize * ($page - 1);
            $rs = $DB->query("SELECT * FROM meihe_user WHERE{$sql} order by zid desc limit $offset,$pagesize");
            while ($res = $DB->fetch($rs)) {
                if ($res['power'] == 2) {
                    $power_name = '<span class="layui-btn layui-btn-xs btn-info">贵族用户</span>';
                } else {
                    $power_name = '<span class="layui-btn layui-btn-xs btn-primary">普通用户</span>';
                }
                echo '<tr><td>' . $res['zid'] . '</td><td><img src="http://q4.qlogo.cn/headimg_dl?dst_uin=' . $res['qq'] . '&spec=640" style="height: 50px;width: 50px" class="img-rounded img-circle img-thumbnail"></td><td>' . $power_name . '</td><td>' . $res['user'] . '</td><td>' . $res['qq'] . '&nbsp;<a href="http://wpa.qq.com/msgrd?v=3&uin=' . $res['qq'] . '&site=qq&menu=yes">[<img src="../assets/icon/qqpay.ico" width="24">]</a></td><td><span class="layui-btn layui-btn-xs btn-primary" style="background:linear-gradient(to right, #7C4DFF,#536DFE,#9575CD);" onclick="recharge(' . $res['zid'] . ')"><font color="white">' . $res['rmb'] . '</font></span></td><td>' . $res['addtime'] . '<br><a href="javascript:setEndtime(' . $res['zid'] . ')" title="点击续期">' . $res['endtime'] . '</a></td><td><input type="checkbox" id="switchs' . $res['zid'] . '" onclick="Active(\'active\',' . $res['zid'] . ')"' . ($res['active'] == 1 ? ' checked ' : ' ') . 'data-switch="success"/><label for="switchs' . $res['zid'] . '" data-on-label="是" data-off-label="否" class="mb-0 d-block"></label></td><td><a href="./userlist.php?mod=edit&zid=' . $res['zid'] . '" class="layui-btn layui-btn-xs btn-info">编辑</a><span class="layui-btn layui-btn-xs btn-primary" onclick="czpass(' . $res['zid'] . ')">重置密码</span><span class="layui-btn layui-btn-xs btn-danger" onclick="userdel(' . $res['zid'] . ')">删除</span><span class="layui-btn layui-btn-xs btn-default" onclick="sso(' . $res['zid'] . ')">登录</span></td></tr>';
            }
            ?>
        </tbody>
    </table>
</div>
<div class="text-center">
    <?php
    #分页
    $pageList = new Page($numrows, $pagesize, 1, $link ?? '');
    echo $pageList->showPage();
    ?>
</div>
<script>
    $("#blocktitle").html('<?php echo $con ?>');
</script>